<!--管理员教师管理页面 -->
<%@page import="org.apache.catalina.tribes.util.TcclThreadFactory"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date" %>
<%@page import="java.sql.*" %>
<%@page import="org.edu.system.DBConnect" %>
<%
	String adm_id = (String) (session.getAttribute("UserName"));
	String sql = "SELECT * FROM administrator WHERE adm_id = '" + adm_id + "'";
	System.out.println(sql);

	Connection con = DBConnect.getCon();
	Statement stmt = null;
	ResultSet rs = null;
	stmt = con.createStatement();
	rs = stmt.executeQuery(sql);//执行命令
	if (rs.next())// 如果记录集非空，表明有匹配的用户ID
	{
		//正常进行
	} else {
		// 否则登录失败
		// response.sendRedirect ( "MyJsp.jsp" );
		response.sendRedirect("login_failure.jsp");
	}
%>
<!DOCTYPE html>
<html>
<head>
<link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet">
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
#Container {
	width: 100%;
	height: 100%;
	margin: 0px auto;
}

#function {
	float: left;
	width: 120px;
	height: 620px:
}

#deal {
	float: left;
	width: 83%;
	height:650px;
}

#info {
	width: 100%;
	height: 30px;
	clear:both
	
}
</style>
</head>
<body>
	<br>
	<form method="get" name="frmLogin" action="LoginServlet">
		<div id="Container">
			<div id="edit">
				<div id="function">
					<input type="button" class="btn btn-success" value="搜索教师记录" onclick="javascript:window.location.href='${ctx}adm_teacher_search.jsp'"/>
					<br><br>
					<input type="button" class="btn btn-primary" value="插入教师记录" onclick="javascript:window.location.href='adm_teacher_insert.jsp'"/>
				</div>
				<div id="deal">
					<%
					PreparedStatement pst = null;
					ResultSet rs1 = null;
					try{
						String sql_select = "SELECT * FROM teacher";
						Connection con1 = DBConnect.getCon();
						request.setCharacterEncoding("utf-8");
						System.out.println(sql_select);
						pst = con1.prepareStatement(sql_select);
						rs1 = pst.executeQuery();
						System.out.println(pst);
						System.out.println(rs1);
					%>
					<table border="1" class="table table-striped table-bordered" style="text-align:'center'">
						<tr>
							<th><font size="2">教师 ID</font></th>
							<th><font size="2">教师名称</font></th>
							<th><font size="2">教师性别</font></th>
							<th><font size="2">教师密码</font></th>
							<th><font size="2">所属院系</font></th>
							<th><font size="2">手机号码</font></th>
							<th><font size="2">身份证信息</font></th>
							<th colspan="2" align="center"><font size="2">数据操作</font></th>
						</tr>
						<%
							while(rs1.next()){
								System.out.println(rs1.getString("tc_id"));
						%>
						<tr>
							<td><font size="2"><%= rs1.getString("tc_id") %></font></td>
							<td><font size="2"><%= rs1.getString("tc_name") %></font></td>
							<td><font size="2"><%= rs1.getString("tc_passwd") %></font></td>
							<td><font size="2"><%= rs1.getString("tc_gender") %></font></td>
							<td><font size="2"><%= rs1.getString("tc_college") %></font></td>
							<td><font size="2"><%= rs1.getString("tc_phone") %></font></td>
							<td><font size="2"><%= rs1.getString("tc_identity") %></font></td>
							<td>
								<input type="button" class="btn btn-danger btn-xs" value="删除"  onclick="javawwscript:if(confirm('确认删除该记录？')){location='adm_teacher_delete.jsp?id=<%=rs1.getString("tc_id")%>'}"/>
							</td>
							<td>				
								<input type="button" class="btn btn-primary btn-xs" value="更新" onclick="javawwscript:if(confirm('确认修改该记录？')){location='adm_teacher_update.jsp?id=<%=rs1.getString("tc_id")%>'}"/>
							</td>
						</tr>
						<%
								}
							} catch (Exception e) {
								out.println(e);
							}
						%>

					</table>
				</div>
			</div>
			<div id="info">
				<%
					session.setMaxInactiveInterval(360);//设置session五分钟销毁
					String strDateFormat = "yyyy-MM-dd HH:mm:ss";
					SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
					Date d = new Date(session.getCreationTime());
					String username = (String) session.getAttribute("UserName");
				%>
				<br>用户登录时间：<%=sdf.format(d)%>
				<br>用户名称：<%=username%>
				<br>session ID：<%=session.getId()%>
			</div>
		</div>
	</form>
</body>
</html>